const typingElement = document.getElementById('typing-effect');
const text = '即将推出';
let index = 0;
let typingInterval;
const typingSpeed = 200; 
const eraseSpeed = 50; 
let cursor;

function type() {
  if (index < text.length) {
    typingElement.textContent += text.charAt(index);
    index++;
    typingInterval = setTimeout(type, typingSpeed);
  } else {
    cursor = document.createElement('span');
    cursor.classList.add('typing-cursor');
    typingElement.appendChild(cursor);
    setTimeout(erase, 1000);
  }
}

function erase() {
  if (index > 0) {
    typingElement.textContent = typingElement.textContent.slice(0, -1);
    index--;
    setTimeout(erase, eraseSpeed);
  } else {
    if (cursor) {
      cursor.style.opacity = 0;
    }
    clearTimeout(typingInterval);
    index = 0;
    typingElement.textContent = '';
    setTimeout(() => {
      if (cursor) {
        cursor.style.opacity = 1;
      }
      type();
    }, 100); 
  }
}

window.onload = function () {
  type();
};